import { request } from '@/utils/request'
import type {
  UserType,
  CodeRes,
  CodeType,
  PatientInfoType,
  PatientList,
  PatientItem
} from '@/types/user'

export const loginByPasswordAPI = (data: object) =>
  request<UserType>('/login/password', 'POST', data)

/**
 * 获取手机验证码
 * @param mobile 手机号
 * @param type 区分验证码的类型
 * @returns Promise对象
 */
export const sendMSMCode = (mobile: string, type: CodeType) =>
  request<CodeRes>('/code', 'GET', { mobile, type })

export const loginByCodeAPI = (mobile: string, code: string) =>
  request<UserType>('/login', 'POST', { mobile, code })

export const registerByCodeAPI = (mobile: string, code: string, password: string) =>
  request<UserType>('/register', 'POST', { mobile, code, password })

/**
 * 我的-获取个人用户信息
 * @returns Promise对象
 */
export const getUserInfoAPI = () => request<PatientInfoType>('/patient/myUser', 'GET')

export const getPatientListAPI = () => request<PatientList>('/patient/mylist')

export const addPatientAPI = (patient: PatientItem) => request('/patient/add', 'POST', patient)

export const editPatientAPI = (patient: PatientItem) => request('/patient/update', 'PUT', patient)

export const delPatientAPI = (id: string) => request(`/patient/del/${id}`, 'DELETE')

/**
 * 消息通知-所有未读数量
 * @returns Promise对象
 */
export const unReadAPI = () => request<number>('/patient/message/unRead/all')

/**
 * 登录--三方登录--qq三方登录
 * @param openId
 * @returns Promise对象
 */
export const loginByQQAPI = (openId: string) =>
  request<UserType>('/login/thirdparty', 'POST', { openId, source: 'qq' })

/**
 * 登录--绑定用户新-三方登录绑定手机号
 * @param data 请求参数
 * @returns
 */
export const bindMobileAPI = (data: { mobile: string; code: string; openId: string }) =>
  request<UserType>('/login/binding', 'POST', data)
